// class Stack {
//     constructor () {
//       this.items = []
//     }
// }


class Stack {
    constructor () {
      this.items = []
    }
    push (element) {
      this.items.push(elememt)
    }
    pop () {
      return this.items.pop()
    }
    peek () {
      return this.items[this.size - 1]
    }
    isEmpty () {
      return this.size === 0
    }
    clear () {
      return this.items = []
    }
    size () {
      return this.items.length
    }
  }


//   使用Stack类
const stack = new Stack()
console.log(stack.isEmpty())  // true
stack.push(1)
stack.push(2)
console.log(stack.peek())     // 2

stack.push(4)
console.log(stack.size())     // 3
console.log(stack.pop())      // 4
console.log(stack.size())     // 2

stack.clear()
console.log(stack.isEmpty())  // true